package com.yun.datastructure.tree.heap.leetcode;

import com.yun.datastructure.tree.heap.Heap;

public class Leetcode295A {
    private Heap left;
    private Heap right;

    public Leetcode295A() {
        left=new Heap(10,true);
        right=new Heap(10,false);
    }

    public void addNum(int num) {
        if(left.getSize()== right.getSize()){
            right.offer(num);
            left.offer(right.poll());
        }else {
            left.offer(num);
            right.offer(left.poll());
        }
    }

    public double findMedian() {
        if(left.getSize()== right.getSize()){
            return (left.peek()+ right.peek())/2.0;
        }else {
            return left.peek();
        }
    }
}
